import pygame, math, sys, random

class bosshelicopter():
    def __init__(self, speed, position, screenSize):
        self.surfaces = []
        for num in range(1, 3):
            surf = pygame.image.load("rsc/Helicopter 2.png")
            surf = pygame.transform.scale(surf, (110,110))
            self.surfaces += [surf]
        self.frame = 0
        self.maxFrame = len(self.surfaces)-1
        self.surface = self.surfaces[self.frame]
        self.rect = self.surface.get_rect()
        self.speed = speed
        self.place(position)
        self.living = True
        self.damage = 100
        if pygame.mixer:
            self.bounceSound = pygame.mixer.Sound("bounce.wav")
        self.screenWidth = screenSize[0]
        self.screenHeight = screenSize[1]
        self.radius = self.rect.width/2
            
    def  __str__(self):
        return "I'm a bosshelicopter " + str(self.rect.center) + str(self.speed) + str(self.living)
     
     
    def place(self, position):
        self.rect.center = position
        
        def move(self):
        self.rect = self.rect.move(self.speed)
        
    def collideFloor(self, screenHeight):
        #print "trying to hit bottom of screen", screenHeight;
        pass

    def collideWall(self, screenWidth, screenHeight):
        if (self.rect.left < 0 
            or self.rect.right > self.screenWidth):
            self.speed[0] = self.speed[0]*-1
        if (self.rect.top < 0 
            or self.rect.bottom >self.screenHeight):
            self.speed[1] = self.speed[1]*-1
        #print "trying to hit edges of screen", screenWidth, screenHeight;
        pass
        
    def collideHelicopter(self, Helicopter):
        if (self.rect.right > Helicopter.rect.left 
            and self.rect.left < Helicopter.rect.right):
            if (self.rect.bottom > Helicopter.rect.top and 
                self.rect.top < Helicopter.rect.bottom):
                if (self.distToPoint(Helicopter.rect.center)
                    < self.radius + Helicopter.radius):  
                    self.living = False
                    return True
        return False
                    
                    
    def collideBullet(self, bullet):        
        if (self.rect.right > bullet.rect.left 
            and self.rect.left < bullet.rect.right):
            if (self.rect.bottom > bullet.rect.top and 
                self.rect.top < bullet.rect.bottom):
                if (self.distToPoint(bullet.rect.center)
                    < self.radius + bullet.radius): 
                    self.living = False
                    bullet.living = False
                    return True 
        return False
        
    def distToPoint(self, pt):
        x1 = self.rect.center[0]
        x2 = pt[0]
        y1 = self.rect.center[1]
        y2 = pt[1]
        return math.sqrt(((x2-x1)**2)+((y2-y1)**2))
        #if pygame.mixer:
        #   self.bounceSound.play()
        